//MINI UI解析
mini.parse();

//同步设置处理器类
function SyncSettingHandler() {
	this.data = {};
	this.service = mini.get("service");
	this.form = new mini.Form("syncSettingForm");
	
	this.load = function(miniwin, data) {
		data = mini.clone(data);
		this.data.syncType = data.syncType;
		
		$.ajax({
			url : __root + "/getSyncObject.do", 
			type : "POST", 
			dataType : "json", 
			success : function(result) {
				if (result.remote) {
					miniwin.setTitle(miniwin.getTitle() + "[<font color='blue'>远程</font>]");
				} else {
					instance.disable();
					miniwin.setTitle(miniwin.getTitle() + "[<font color='blue'>本地</font>]");
				}
				
				if (result.service.length > 0) {
					instance.service.setData(result.service);
					instance.service.setValue(result.service[0].address);
				}
			}, 
			error : function (request) {
				instance.readonly();
				mini.alert(request.responseText, "系统提示");
			}
		});
	};
	
	this.sync = function() {
		this.form.validate();
		
		if (this.form.isValid()) {
			var data = this.form.getData();
			data.syncType = this.data.syncType;
			
			var json = mini.encode(data);
			$.ajax({
				url : __root + "/syncSetting.do", 
				type : "POST", 
				data: {
		        	data: json,
		        	lslUser: gbOperateUser,
		    		lslAddress: gbOperateIp
		        },
				dataType : "json", 
				success : function(result) {
					mini.alert(result.message, "系统提示");
				}, 
				error : function (request) {
					mini.alert(request.responseText, "系统提示");
				}
			});
		}
	};
	
	this.close = function(action) {
		if (CloseOwnerWindow) {
			CloseOwnerWindow(action);
		} else {
			window.close();
		}
	};
	
	this.readonly = function() {
		this.service.readOnly = true;
	};
	
	this.disable = function() {
		this.service.disable();
	};
};

//同步设置处理器全局实例
var instance = new SyncSettingHandler();

//定义同步按钮点击事件处理程序
function onSyncClick(e) {
	instance.sync();
}

//定义关闭按钮点击事件处理程序
function onCancelClick(e) {
	instance.close("cancel");
}
